package com.deep.spring.v4;

import lombok.extern.slf4j.Slf4j;

import javax.annotation.PostConstruct;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@Slf4j
@WebFilter
//@Component
public class AuthFilter implements Filter {

    @PostConstruct
    public void test() {
        log.error("AuthFilter");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        log.debug("start to auth request validate...111");
        HttpServletRequest req = (HttpServletRequest) servletRequest;
        String token = req.getHeader("token");
//        req.setCharacterEncoding("utf8");
        String token2 = req.getParameter("token");
        System.out.println(token2);
        if (token != null) {
            //    :TODO check token
            log.info("auth success");
        } else {
            log.error("auth failed");
        }

        filterChain.doFilter(servletRequest, servletResponse);

    }
}
